<?php
require_once('../../config.php');
require_once('security.php');
  
  if (isset($_POST['submit'])) 
  { // Handle the form

   
    $response = "";  
    
    $maintheme = $_POST['thetheme'];
    $maincssfile = "<link rel=\"stylesheet\" href=\"" . $wwwroot . "/cms/admin/theme/" . $maintheme . "/mainstyle.css\" type=\"text/css\" media=\"screen\" />";
     // Path to the .php file (to write the theme)
      $filename = "theme/" .$maintheme ."/maintheme.php";
    // Write the contents
        $fp = fopen($filename, "w") or die("Couldn't open $filename.");
        fwrite($fp, $maincssfile. "\n" );
        fclose($fp);
       
    
    $admintheme = $_POST['thetheme'];
    $admincssfile = "<link rel=\"stylesheet\" href=\"theme/" . $admintheme . "/adminstyle.css\" type=\"text/css\" media=\"screen\" />";
     // Path to the .php file (to write the theme)
      $filename = "theme/" .$maintheme ."/admintheme.php";
    // Write the contents
        $fp = fopen($filename, "w") or die("Couldn't open $filename.");
        fwrite($fp, $admincssfile. "\n" );
        fclose($fp);
       
       // Feedback
        $response = "The theme file was updated.";
        //$success = "yes";
    

  }
 
?>

<?php $thisPage = "changetheme"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Change the theme</title>
<meta name="robots" content="noindex,nofollow" />
<?php require_once('theme/admintheme.php');?>
</head>
<body>

<div id="wrap">
<?php include_once('navigation.php'); ?>

<b>Select Theme</b><br />
<form name="linkform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Select the theme, then click "Get the theme".<br />
<?php  
  echo '<p><b>List of themes:</b></p>';
  $dirname = "theme";
  $dh = opendir($dirname);
  
  echo '<select style="width:120px;" name="thetheme" />';
  while (false !== ($file = readdir($dh))) 
  {
    //if (strstr($file, '.txt')&& strstr($file, 'extra')) 
    if (!strstr($file, '.php')&& strstr($file, 'theme')) 
    {
        if ((isset($_POST['submit'])) && ($_POST['thetheme']==$file))
        {
        echo '<option selected="selected" value="' . $file . '">' . $file . '</option>';
        }
        else
        {
        echo '<option value="' . $file . '">' . $file . '</option>';
        }
    }
  }
  closedir($dh);
echo '</select>';
?>

<!-- >
URL<br />
http:// <input type="text" name="url" id="thispage2" size="40" value="<?php if(($success=="no")&&(isset($_POST['submit']))) echo $_POST['url']; ?>" maxlength="60" />
<br />
Desired link text<br />
<input type="text" name="linktext" id="linktext" size="40" value="<?php if (($success=="no")&& (isset($_POST['submit']))) echo $_POST['linktext']; ?>" maxlength="60" />
< -->
<br />
<br />
<input type="submit" name="submit" value="Get the Theme" />
</form>

<?php if (isset($response)) {echo $response;} ?>
<?php //echo $x; ?>
<?php //echo "d".$url; ?>
<?php //print_r($line_array); ?>
<?php //print_r($checklink); ?>
<div style="clear: both;"></div>
</div>

</body>
</html>
